package com.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;


@Component
@Slf4j
@Aspect
public class MyAspectDemo {
    //前置通知
    @Before("@annotation(com.example.aop.config.MyAspect)")
    public void before() {
        log.info("MyAspect -> before...");
    }
    //后置通知
    @After("@annotation(com.example.aop.config.MyAspect)")
    public void after() {
        log.info("MyAspect -> after...");
    }
}


//
//@Component
//@Slf4j
//@Aspect
//public class MyAspectDemo {
//    @Around("@annotation(com.example.aop.config.MyAspect)")
//    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
//        log.info("do around before...");
//        Object o = null;
//        try {
//            o = joinPoint.proceed();
//        }catch (Throwable e) {
//            log.error("发生异常, e", e);
//        }
//        log.info("do around after...");
//        return o;
//    }
//
//    @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
//    public Object doAround2(ProceedingJoinPoint joinPoint) throws Throwable {
//        log.info("RequestMapping do around before...");
//        Object o = null;
//        try {
//            o = joinPoint.proceed();
//        }catch (Throwable e) {
//            log.error("RequestMapping 发生异常, e", e);
//        }
//        log.info("RequestMapping do around after...");
//        return o;
//    }
//}
